// 包含多个基于state的getter计算属性的对象
export default {
  totalCount (state) {
    // reduce 类似于迭代，对数组进行遍历，函数的第一个参数得到的是计算后的结果，0表示初始值为0
    return state.cartFoods.reduce((preTotal, food) => preTotal + food.count, 0)
  },
  totalPrice (state) {
    return state.cartFoods.reduce((preTotal, food) => preTotal + food.count * food.price, 0)
  },

  positiveSize (state) {
    return state.ratings.reduce((preTotal, rating) => preTotal + (rating.rateType === 0 ? 1 : 0), 0)
  }
}
